<template>
  <el-dialog title="收货地址" :visible.sync="dialogTableVisible">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="姓名" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input v-model="ruleForm.address"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogTableVisible = false">取 消</el-button>
      <el-button type="primary" @click="handleConfirmDialog">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    formData: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      rules: {
        name: [{ required: true, message: "请输入名称", trigger: "blur" }],
        address: [{ required: true, message: "请输入地址", trigger: "blur" }],
      },
      ruleForm: {},
    };
  },
  watch: {
    formData(val) {
      this.ruleForm = val;
    },
  },
  computed: {
    dialogTableVisible: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit("input", val);
      },
    },
  },
  methods: {
    handleConfirmDialog() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          console.log(this.formData, "校验通过");
          this.$emit("input", false);
          this.$emit("confirm", this.formData);
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
